home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
pctj0487.arc
/
FASTBLK.ASM
< prev
next >
Wrap
Assembly Source File
|
1987-02-20
|
2KB
|
51 lines
; Fast (32-bit) block move for 80386 computers.
; Calling program selects 16- or a 32-bit move.
; Calling program must be sure 80386 is present for 32-bit move.
; For best performance, source and destination blocks should begin on
; doubleword (for 32-bit move) or word (for 16-bit move) boundary.
; Automatically handles block sizes with odd words and bytes.
; Input: DS:SI = source.
; ES:DI = destination.
; CX = number of bytes to move.
; AL = 1 to perform fast 32-bit move (for 80386 only),
; 0 to perform standard 16-bit move (for 8088/86/286).
; Results:
; CX & BX destroyed, SI points to the byte after the end of the
; source block, DI points to the byte after the end of the
; destination block, direction flag cleared.
;
cseg segment word public 'CODE'
assume cs:cseg
public FastBlockMove
FastBlockMove proc near
cld
xor bx,bx ;clear odd-size flags
shr cx,1 ;convert move size to words
jnc CheckFor32BitMove
mov bl,1 ;indicate odd byte
CheckFor32BitMove:
and al,al ;has caller requested a 32-bit move?
jz DoBlockMove
shr cx,1 ;32-bit move -- convert to dbl words
jnc Do32BitMove
mov bh,1 ;indicate odd word
Do32BitMove:
db 66h ;prefix to make the default size for the
; following instruction 32 bits.
DoBlockMove:
rep movsw ;move the block -- the move normally defaults
; to 16 bits at a time, but if the size
; prefix was executed, 32 bits will be
; moved on each iteration
and bh,bh ;is there an odd word?
jz TestOddByte
movsw ;if so, move it
TestOddByte:
and bl,bl ;is there an odd byte?
jz Exit
movsb ;if so, move it
Exit: ret
FastBlockMove endp
cseg ends
end